package com.csd.jwt.config;

import com.csd.jwt.interceptor.TokenInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @className: InterceptorConfig
 * @description:
 * @author: 刘子奇
 * @date: 2019/12/9 17:57
 **/
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {

    @Autowired
    TokenInterceptor tokenInterceptor;
//
//    @Override
//    public void addCorsMappings(CorsRegistry registry) {
//        //允许全部请求跨域
//        registry.addMapping("/**")
//                .allowedOrigins("*")
//                //.allowedOrigins("http://localhost:8080")
////                .allowedOrigins("http://localhost:8088")
//                .allowedMethods("*")
//                .allowCredentials(true).maxAge(3600);
//
//    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(tokenInterceptor)
                .excludePathPatterns("/api-auth/login")
                .addPathPatterns("/**");
    }
}
